//
//  BlockAlertView.m
//  fmapp
//
//  Created by zhouyang on 14-8-31.
//  Copyright (c) 2014年 CheDong Technology Co., Ltd. All rights reserved.
//

#import "BlockAlertView.h"
#define kMAlertViewTextFieldHeight 30.0
#define kMAlertViewMargin 10.0

@implementation BlockAlertView
@synthesize textFiled = m_textField;
- (id)initWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString*)otherButtonTitles block:(TouchBlock)block{
    self = [super initWithTitle:title message:message delegate:self cancelButtonTitle:cancelButtonTitle otherButtonTitles:otherButtonTitles, nil];//注意这里初始化父类的
    if (self) {
        self.block = block;
    }
    return self;
}

- (id)initInputViewWithTitle:(NSString *)title
                     message:(NSString *)message
           cancelButtonTitle:(NSString *)cancelButtonTitle
           otherButtonTitles:(NSString*)otherButtonTitles
                       block:(TouchBlock2)block2
{
    self = [super initWithTitle:title message:message delegate:self cancelButtonTitle:cancelButtonTitle otherButtonTitles:otherButtonTitles, nil];//注意这里初始化父类的
    if (self)
    {
        self.block2 = block2;
        [self setAlertViewStyle:UIAlertViewStylePlainTextInput];
    }
    return self;
}


//#pragma mark -AlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    //这里调用函数指针_block(要传进来的参数);
    if (_block)
    {
        _block(buttonIndex);
    }
    
    if (_block2)
    {
        UITextField *tf=[alertView textFieldAtIndex:0];
        if (tf)
        {
            _block2(buttonIndex,tf.text);
        }
    }
}

@end
